import requests
from comment.get_header_tools import get_req_header  # 导包 获取令牌


# 定义接口对象
class DepManagerApi:

    # 添加部门
    @staticmethod
    def add_dep(req_header, req_body):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/company/department",
                             headers=req_header, json=req_body)

        return resp

    # 查询
    @staticmethod
    def query_dep(dep_id, req_header):
        resq = requests.get(url="http://ihrm2-test.itheima.net/api/company/department/" + dep_id,
                            headers=req_header)
        return resq

    # 修改
    @staticmethod
    def modifiy_dep(dep_id, req_header, req_body):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/company/department/" + dep_id,
                            headers=req_header, json=req_body)

        return resp

    @staticmethod
    def delete_dep(dep_id, req_header):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/company/department/" + dep_id,
                               headers=req_header)
        return resp


if __name__ == '__main__':
    # 自测 添加
    req_header = get_req_header()  # 令牌
    req_body = {"name": "测试部", "code": "00001"}  # 请求体
    resp = DepManagerApi.add_dep(req_header, req_body)
    print(resp.json())

# 提取部门id

    dep_id = resp.json().get("data").get("id")
    print(dep_id)

    # 自测查询
    resp = DepManagerApi.query_dep(dep_id, req_header)
    print(resp.json())
